# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=reapack
pkgver=1.2.4.3
pkgrel=1
pkgdesc='Package manager for the Reaper DAW'
arch=('loong64' 'x86_64')
url='https://reapack.com'
license=('GPL3' 'LGPL3')
depends=(
  'glibc'
  'gcc-libs'
  'openssl'
  'zlib'
  'reaper'
  'libxml2'
  'curl'
  'sqlite'
)
makedepends=(
  'git'
  'cmake'
  'boost'
  'ruby'
  'php'
  'catch2'
)
install='reapack.install'
_commit='7ece4e058436959d977ab387aa86bf73ac5b2278'
source=(
  "$pkgname::git+https://github.com/cfillion/reapack#commit=$_commit"
  'github.com-justinfrankel-wdl::git+https://github.com/justinfrankel/WDL'
  'github.com-justinfrankel-reaper-sdk::git+https://github.com/justinfrankel/reaper-sdk'
  'ftbfs-gcc13.patch'
)
b2sums=('SKIP'
        'SKIP'
        'SKIP'
        'f31e2c4cbb7d32092e165687f0acb95591ea1f199234394a3e6d5890bc34fde8b157014c815989f5a0456b8813c2a4a9efa2dfc111a5cee003470c0cf32f3cfe')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # prepare git submodule(s)
  git submodule init
  git config submodule.vendor/WDL.url "$srcdir/github.com-justinfrankel-wdl"
  git config submodule.vendor/reaper-sdk.url "$srcdir/github.com-justinfrankel-reaper-sdk"
  git -c protocol.file.allow=always submodule update

  # FTBFS due to catch2 v3 not being in the repos yet
  # so we have to use an older version
  git revert --no-commit d551e255fe79ea1e463fe757554a55bf5adf5058

  # FTBFS: FS#77178
  git cherry-pick --no-commit f2806c95ba16549e969581429d1fc51616c68796

  # FTBFS: GCC13
  # https://gcc.gnu.org/gcc-13/porting_to.html
  patch -p1 -i "$srcdir/ftbfs-gcc13.patch"
}

build() {
  cd "$pkgname"

  cmake \
    -B build \
    -DCMAKE_BUILD_TYPE=Release

  cmake --build build
}

check() {
  make -C "$pkgname/build" test
}

package() {
  cd "$pkgname"

  # plugin
  install -vDm755 -t "$pkgdir/usr/lib/$pkgname" "build/reaper_reapack-$CARCH.so"

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md
}
